package com.controller;

import com.pojo.Order;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.GetMapping;

import javax.annotation.Resource;

@Component
public class OrderController {
    @Resource
    private RabbitTemplate rabbitTemplate;


    /*@RabbitListener(queuesToDeclare = {@Queue("order")})
    public void getOrder(Order order) {
        System.out.println("编号1: " + order.getoId() + "客户1:" + order.getuId() + "创建时间1:" + order.getTime());
    }

    @GetMapping("/addOrders")
    @RabbitListener(queuesToDeclare = {@Queue("order")})
    public void getOrder1(Order order) {
        System.out.println("编号2: " + order.getoId() + "客户2:" + order.getuId() + "创建时间2:" + order.getTime());
    }*/

    /*@RabbitListener(
            bindings = @QueueBinding(value = @Queue("order1"),
            exchange = @Exchange(name = "fanoutExchange",type = ExchangeTypes.FANOUT)
            )
    )
    public void getOrder(Order order) {
        System.out.println("编号1: " + order.getoId() + "客户1:" + order.getuId() + "创建时间1:" + order.getTime());
    }*/

    /*@RabbitListener(
            bindings = @QueueBinding(value = @Queue("order2"),
                    exchange = @Exchange(name = "fanoutExchange",type = ExchangeTypes.FANOUT)
            )
    )*/
    /*@RabbitListener(queuesToDeclare = {@Queue("order2")})
    public void getOrder2(Order order) {
        System.out.println("编号2: " + order.getoId() + "客户2:" + order.getuId() + "创建时间2:" + order.getTime());
    }*/


    @RabbitListener(
            bindings = @QueueBinding(value = @Queue("order1"),
            key = {"success"},
            exchange = @Exchange(name = "directExchange",type = ExchangeTypes.FANOUT)
            )
    )
    public void getOrder(Order order) {
        System.out.println("编号1: " + order.getoId() + "客户1:" + order.getuId() + "创建时间1:" + order.getTime());
    }

    @RabbitListener(
            bindings = @QueueBinding(value = @Queue("order1"),
                    key = {"success"},
                    exchange = @Exchange(name = "directExchange",type = ExchangeTypes.FANOUT)
            )
    )
    public void getOrder1(Order order) {
        System.out.println("编号2: " + order.getoId() + "客户2:" + order.getuId() + "创建时间2:" + order.getTime());
    }

    @RabbitListener(queuesToDeclare = {@Queue("order2")})
    public void getOrder2(Order order) {
        System.out.println("编号3: " + order.getoId() + "客户3:" + order.getuId() + "创建时间3:" + order.getTime());
    }
}
